# encoding:utf-8

import simplejson
import jinja2
# import werkzeug.utilsfrom openerp import http
from openerp.http import request

from openerp.addons.web import http
# from opernerp.http import Response
# from openerp.addons.web.http import request
# from openerp.addons.eroad_mweb.controllers import mweb_public
from openerp import SUPERUSER_ID
import datetime

import urllib
# from eroad_odoo_utils import eroad_utils
# from openerp.addons import eroad_qywechat_api
# from openerp.addons import eroad_gzwechat_api
# from eroad_odoo_utils.eroad_wechat_util import qywechat_sdk, gzwechat_sdk,jssdk_sign
# from eroad_bracelet_web import _get_wx_sdk_jsapi_conf as _get_wx_sdk_jsapi_conf

# from openerp.addons.eroad_qywechat_api import conf
import codecs

import itertools

loader = jinja2.PackageLoader('openerp.addons.eroad_bracelet_web_json', 'html')
env = jinja2.Environment(loader=loader, autoescape=True)
env.filters["json"] = simplejson.dumps



class Recommend_doctor_controller(http.Controller):

    @http.route("/hellotest/")
    def hello(self):
        return "Hello World"


    #范例 http://localhost:48269/recommenddoctor/doctor/doctorlist/newjson?agentid=7&status=4
    @http.route('/recommenddoctor/doctor/doctorlist/newjson', type='http', auth="user", cors='*')
    def doctor_patient_list_new(self, req, **kw):
        method = req.httprequest.method
        if method == "GET" or method == "POST":
            # print req.params
            pn = req.params.get('page')
            if (pn==''): pn = 0
            if (pn is None): pn=0
            pn = int(pn)
            if pn<=0: pn = 1

            ps = req.params.get('limit')
            if (ps==''): ps = 0
            if (ps is None): ps = 0
            ps = int(ps)
            if ps <=0: ps = 1000

            agentid = req.params.get('agentid')
            if (agentid is None): agentid = -1
            agentid = int(agentid)

            #1是已加入 4是未加入
            status = req.params.get('status')
            if (status is None): status = 1
            status = int(status)

            # print method, kw, req.params, pn, ps, docid #, kw["pn"]
            pc = 0

            registry = req.registry

            #分页 begin
            activecountsql = "select * from recomm_doctor "

            with registry.cursor() as cr:
                #mazh 2010-10-12 修改
                cr.execute(activecountsql)
                all_doctors = cr.dictfetchall()
                #indoctors = cr.dictfetchall()
            #adata = combine_doctordata(adoctors)
            #indata = combine_doctordata(indoctors)

            success = 'true'

            html = {
                'success':success,
                'acount':'8',
                'incount':'8',
                'pn':pn,
                'ps':ps,
                'title': '代表的医生',
                'header':'医生列表',
                'agent':agentid,
                'data':all_doctors,
                'indata':all_doctors,
            }
            html = simplejson.dumps(html)
            return request.make_response(html,{
                'Cache-Control': 'no-cache',
                'Content-Type': 'text/html; charset=utf-8',
                'Access-Control-Allow-Origin': '*',
                'Origin': '*',
                'Access-Control-Allow-Methods': 'GET,POST',
                'Access-Control-Allow-Headers': 'Referer, Accept, Origin, User-Agent'
            })
        else:
            return "{%s}" % (method)













